package com.app.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.app.common.*;

import com.app.dto.ImageDTO;
import com.app.mapper.*;
import com.app.model.*;
import com.app.service.*;
import com.app.util.*;

import com.app.vo.CustomerListVo;
import com.app.vo.ExperienceVo;
import com.app.vo.JobFairSceneVo;
import com.app.vo.JobPublishVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencentcloudapi.asr.v20190614.models.SentenceRecognitionRequest;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.docx4j.wml.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@Controller
@NoArgsConstructor
@AllArgsConstructor
@Data
public class JobPublishController {
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    private JobPublishService jobPublishService;
    @Autowired
    ComRecruitersService comRecruitersService;
    @Autowired
    EnterpriseService enterpriseService;
    @Autowired
    IndustryService industryService;
    @Autowired
    PositionService positionService;
    @Autowired
    UserMapper userMapper;
    @Autowired
    CusWorkExperienceService cusWorkExperienceService;
    @Autowired
    UserService userService;
    @Autowired
    CustomerMapper customerMapper;
    @Autowired
    LookMeService lookMeService;
    @Autowired
    private WorkApplyMapper mapper;
    @Autowired
    WorkApplyService workApplyService;
    @Autowired
    CusEducationService cusEducationService;
    @Autowired
    JobFairCompanyPostService jobFairCompanyPostService;
    @Autowired
    private CustomerService customerService;

    @Autowired
    private JobIntentionService jobIntentionService;
    @Autowired
    private StreetService streetService;
    @Autowired
    private ComResumeNumberService comResumeNumberService;
    @Autowired
    public JobFairSceneService jobFairSceneService;
    @Autowired
    private JobFairCompanyService jobFairCompanyService;
    @Resource
    private SkillTrainingService skillTrainingService;
    //根据id查询
    @RequestMapping(value = "findAllJobById", method = RequestMethod.GET)
    public Result<Object> selectJobsById(int id, HttpServletRequest request) throws ParseException {
        String token = request.getHeader("token");
        UserModel user = null;
        if (token != null) {
            String mobile = TokenUtils.verify(token);
            user = userService.getUserByMobile(mobile);
        }
        return Result.success(jobPublishService.selectJobsById(id, user));

    }


    @PostMapping(value = "addAndUpdateJob")
    public Result<Object> addAndUpdateJob(@RequestParam("jobTitle") String jobTitle,
                                          @RequestParam("jobType") int jobType,
                                          @RequestParam("expId") int expId,
                                          @RequestParam("eduId") int eduId,
                                          @RequestParam(required = false) String minSalary,
                                          @RequestParam(required = false) String maxSalary,
                                          @RequestParam("jobDescription") String jobDescription,
                                          @RequestParam("jobAddress") String jobAddress,
                                          @RequestParam("id") int id,
                                          @RequestParam("recruitType") int recruitType,
                                          @RequestParam("longitude") double longitude,
                                          @RequestParam("latitude") double latitude,
                                          @RequestParam("startTime") String startTime,
                                          @RequestParam("endTime") String endTime,
                                          @RequestParam("keyword") String keyword,
                                          @RequestParam("worry") boolean worry,
                                          @RequestParam("jobNumber") Integer jobNumber,
                                          @RequestParam(required = false) Integer salaryNegotiable,
                                          @RequestParam(required = false) String welfare,
                                          HttpServletRequest request
    ) {
        String token = request.getHeader("token");
        if (token == null) {
            return Result.error(405, "token不存在");

        }
        String mobile = TokenUtils.verify(token);
        UserModel user = userService.getUserByMobile(mobile);

        if (user == null) {
            return Result.error(405, "用户不存在");
        }

        JobPublishModel jobPublishModel = jobPublishService.findJobByUserAndTitle(user.getRId(), jobTitle, minSalary, maxSalary);
        if (jobPublishModel != null) {
            return Result.error(201, "该岗位已发布，请勿重复发布");
        }
        ComRecruitersModel com = comRecruitersService.getComRecruitersById(user.getRId());
        JobPublishModel jobPublish = new JobPublishModel();
        jobPublish.setJobTitle(jobTitle);
        jobPublish.setJobType(jobType);
        jobPublish.setExpId(expId);
        jobPublish.setEduId(eduId);
        if (worry) {
            jobPublish.setWorry(1);
        } else {
            jobPublish.setWorry(0);
        }
        if (salaryNegotiable == 0) {
            jobPublish.setMinSalary(Integer.parseInt(minSalary));
            jobPublish.setMaxSalary(Integer.parseInt(maxSalary));
        }
        jobPublish.setJobDescription(jobDescription);
        jobPublish.setJobAddress(jobAddress);
        jobPublish.setLongitude(longitude);
        jobPublish.setLatitude(latitude);
        jobPublish.setStartTime(startTime);
        jobPublish.setEndTime(endTime);
        jobPublish.setKeyword(keyword);
        jobPublish.setEnrollId(com.getComId());
        jobPublish.setRecId(com.getId());
        jobPublish.setId(id);
        jobPublish.setJobNumber(jobNumber);
        jobPublish.setRecruitType(recruitType);
        jobPublish.setWelfare(welfare);
        jobPublish.setSalaryNegotiable(salaryNegotiable);
        JSONObject json = WXLonginUtil.getGeocoder(latitude, longitude);
        JSONObject addressReference = (JSONObject) json.get("address_reference");
        JSONObject town = (JSONObject) addressReference.get("town");
        String title = (String) town.get("title");
        List<StreetModel> streetModelList = streetService.getAll();
        for (int i = 0; i < streetModelList.size(); i++) {
            if (title.equals(streetModelList.get(i).getName())) {
                jobPublish.setStreetId(streetModelList.get(i).getId());
                break;
            }
        }
        try {
            if (id > 0) {
                jobPublish.setRecruitState(1);
                jobPublishService.update(jobPublish);
            } else {
                jobPublish.setCrtTime(CommonHelp.getNowTimestamp());
                jobPublish.setRecruitState(1);
                jobPublishService.insertJobs(jobPublish);
                jobPublishService.addPublishMsg(com, jobPublish);//发送短信通知
            }

        } catch (Exception e) {
            System.out.println(e);
        }
        return Result.success(null);
    }

    //模糊查询招聘信息
    @GetMapping("/getPublishByOpenUp")
    public Result<Object> getPublishByOpenUp(HttpServletRequest request) throws ParseException {
        String token = request.getHeader("token");
        if (token == null) {
            return Result.error(405, "token不存在");

        }
        String mobile = TokenUtils.verify(token);
        UserModel user = userService.getUserByMobile(mobile);

        if (user == null) {
            return Result.error(405, "用户不存在");
        }
        ComRecruitersModel com = comRecruitersService.getComRecruitersById(user.getRId());
        List<JobPublishModel> modelList = jobPublishService.getJobPublishListByExOpen(com.getId());

        return Result.success(modelList);
    }

    //模糊查询招聘信息
    @GetMapping("/getPublish")
    public Result<Object> getWorkExp(HttpServletRequest request,
                                     @RequestParam(required = false) String jobTitle,//岗位名称
                                     @RequestParam(required = false) Integer comId,//企业ID
                                     @RequestParam(required = false) Integer jobType,//行业ID
                                     @RequestParam(required = false) Integer jobLevel,//行业级别
                                     @RequestParam(required = false) Integer recruitType,//招聘类型
                                     @RequestParam(required = false) Integer salaryId,//薪资id
                                     @RequestParam(required = false) String eduId,//学历id
                                     @RequestParam(required = false) Integer expId,//经验id
                                     @RequestParam(required = false) Integer salaryMax,//薪资最高
                                     @RequestParam(required = false) Integer salaryMin,//薪资最低
                                     @RequestParam(required = false) String keyword,//关键字
                                     @RequestParam(required = false) Integer orderDate,//时间排序
                                     @RequestParam(required = false) Integer orderEducation,//学历排序
                                     @RequestParam(required = false) Integer orderWages,//薪资排序
                                     @RequestParam(required = false) String jobTypes,//多行业筛选
                                     @RequestParam(required = false) Integer scaleId,//规模ID
                                     @RequestParam(required = false) Integer natureId,//性质ID
                                     @RequestParam(required = false) Double longitude,//经度
                                     @RequestParam(required = false) Double latitude,//纬度
                                     @RequestParam(required = false) Integer orderDistance,//距离排序
                                     @RequestParam(required = false) Integer streetId,//街道id
                                     @RequestParam(required = false) String searchName,//搜索字段
                                     Integer page, Integer limit

    ) throws ParseException {
        JobPublishModel model = new JobPublishModel();
        model.setSearchName(searchName);
        model.setJobTitle(jobTitle);
        if (recruitType != null) {
            model.setRecruitType(recruitType);
        }
        if (streetId != null && streetId > 0) {
            model.setStreetId(streetId);
        }
        if (longitude != null && longitude > 0) {
            model.setLongitude(longitude);
        }
        if (latitude != null && latitude > 0) {
            model.setLatitude(latitude);
        }
        if (orderDistance != null && orderDistance > 0) {
            model.setOrderDistance(orderDistance);
        }
        if (jobType != null) {
            model.setJobType(jobType);
        }
        if (jobLevel != null) {
            model.setLevel(jobLevel);
        }
        if (jobLevel != null && jobType != null && jobLevel == 2) {
            PositionModel positionModel = positionService.getModelById(jobType);
            model.setFatherCode(positionModel.getPostCode());
        }
        if (comId != null) {
            model.setEnrollId(comId);
        }
        if (StringTool.isNotEmpty(eduId)) {
            List<Integer> eduIdList = new ArrayList<>();
            String[] strs = eduId.split(",");
            for (int i = 0; i < strs.length; i++) {
                eduIdList.add(Integer.valueOf(strs[i]));
            }
            model.setEduIds(eduIdList);
        }

        if (expId != null) {
            model.setExpId(expId);
        }
        if (keyword != null) {
            model.setKeyword(keyword);
        }
        if (StringTool.isNotEmpty(jobTypes)) {
            List<Integer> jobtypeList = new ArrayList<>();
            String[] strs = jobTypes.split(",");
            for (int i = 0; i < strs.length; i++) {
                jobtypeList.add(Integer.valueOf(strs[i]));
            }
            model.setJobTypes(jobtypeList);
        }
        if (scaleId != null) {
            model.setScaleId(scaleId);
        }
        if (natureId != null) {
            model.setNatureId(natureId);
        }
        model.setRecruitState(3);
        model.setOrderDate(orderDate);
        model.setOrderWages(orderWages);
        model.setOrderEducation(orderEducation);
        if (salaryId != null) {
            for (int k = 0; k < SalaryTool.SALARY_VO_LIST.size(); k++) {
                if (salaryId == SalaryTool.SALARY_VO_LIST.get(k).getId()) {
                    if (salaryId == 1) {
                        salaryMax = 1;
                        salaryMin = 0;
                        break;
                    }
                    if (salaryId == 9) {
                        salaryMax = 100;
                        salaryMin = 25;
                        break;
                    }
                    if (salaryId > 1 && salaryId < 9) {
                        salaryMin = Integer.parseInt(StringUtils.substringBefore(SalaryTool.SALARY_VO_LIST.get(k).getData(), "-"));
                        salaryMax = Integer.parseInt(StringUtils.substringAfter(SalaryTool.SALARY_VO_LIST.get(k).getData(), "-"));
                        break;
                    }

                }
            }
        }
        model.setMinSalary(salaryMin);
        model.setMaxSalary(salaryMax);
        model.setRecruitState(3);
        model.setPage((page - 1) * limit);
        model.setLimit(limit);
        String token = request.getHeader("token");
        List<JobIntentionModel> intentionModelList = new ArrayList<>();
        if (StringTool.isNotEmpty(token)) {
            String mobile = TokenUtils.verify(token);
            UserModel user = userService.getUserByMobile(mobile);
            CustomerModel cus = customerService.getCustomerById(user.getCId());
            intentionModelList = jobIntentionService.getIntentionListByCustomerId(cus.getId());
        }
        if ((orderDistance == null || orderDistance == 0) && intentionModelList != null && intentionModelList.size() > 0 && (orderEducation == null && orderDate == null && orderWages == null)) {
            List<Integer> jobtypeList = new ArrayList<>();
            for (int i = 0; i < intentionModelList.size(); i++) {
                jobtypeList.add(intentionModelList.get(i).getPost());
            }
            model.setPostIds(jobtypeList);
        }
        List<JobPublishModel> modelList = jobPublishService.getJobPublishListByModel(model);
        int count = jobPublishService.getJobPublishCountByModel(model);
        if (modelList != null) {
            List<ComResumeNumberModel> crnModelList = comResumeNumberService.getAllList();
            for (int i = 0; i < modelList.size(); i++) {
                modelList.get(i).setJobTypeText(positionService.getModelById(modelList.get(i).getJobType()).getJobTitle());
                ComRecruitersModel com = comRecruitersService.getComRecruitersById(modelList.get(i).getRecId());
                if (com != null) {
                    EnterpriseModel enterprise = enterpriseService.findModelById(com.getComId());
                    if (enterprise.getWelfare() != null && enterprise.getWelfare() != "") {
                        String[] str = enterprise.getWelfare().split(",");
                        List<String> welfareList = new ArrayList<>();
                        for (int j = 0; j < str.length; j++) {
                            welfareList.add(str[j]);
                        }
                        enterprise.setWelfareList(welfareList);
                    }
                    com.setEnterprise(enterprise);
                    IndustryModel industryModel = industryService.getModelByCode(enterprise.getEnterpriseType());
                    if (industryModel != null) {
                        enterprise.setEnterpriseTypeText(industryModel.getIndustryName());
                    }
                    for (int j = 0; j < ScaleTool.SCALE_VO_LIST.size(); j++) {
                        if (enterprise.getScaleId() != null && enterprise.getScaleId() == ScaleTool.SCALE_VO_LIST.get(j).getId()) {
                            enterprise.setScaleName(ScaleTool.SCALE_VO_LIST.get(j).getData());
                        }
                    }
                    com.setUser(userService.getUserByRId(com.getId()));
                    modelList.get(i).setComRecruiters(com);
                }

                if (modelList.get(i).getDistance() != null) {
                    String distance = String.format("%.1f", modelList.get(i).getDistance());
                    modelList.get(i).setDistances(distance);
                }

                for (int j = 0; j < crnModelList.size(); j++) {
                    if (modelList.get(i).getId() == crnModelList.get(j).getPid()) {
                        if (crnModelList.get(j).getNumber() >= 3) {
                            modelList.get(i).setIsHeat(1);
                        }
                    }
                }
            }

        }
        JobPublishVo vo = new JobPublishVo();
        vo.setList(modelList);
        vo.setCount(count);
        return Result.success(vo);
    }

    @GetMapping("/getPublishRecommend")
    public Result<Object> doClosePublish(Integer page, Integer limit, Integer jobType) {

        JobPublishModel model = new JobPublishModel();
        model.setPage(page);
        model.setLimit(limit);
        model.setJobType(jobType);
        Page<JobPublishModel> modelPage = jobPublishService.getModelByType(model);
        List<JobPublishModel> modelList = modelPage.getRecords();
        int count = (int) modelPage.getTotal();
        if (modelList != null) {
            for (int i = 0; i < modelList.size(); i++) {
                ComRecruitersModel com = comRecruitersService.getComRecruitersById(modelList.get(i).getRecId());
                if (com != null) {
                    EnterpriseModel enterprise = enterpriseService.findModelById(com.getComId());
                    if (enterprise.getWelfare() != null && enterprise.getWelfare() != "") {
                        String[] str = enterprise.getWelfare().split(",");
                        List<String> welfareList = new ArrayList<>();
                        for (int j = 0; j < str.length; j++) {
                            welfareList.add(str[j]);
                        }
                        enterprise.setWelfareList(welfareList);
                    }
                    com.setEnterprise(enterprise);
                    com.setUser(userService.getUserByRId(com.getId()));
                    modelList.get(i).setComRecruiters(com);
                }
            }

        }

        JobPublishVo vo = new JobPublishVo();
        vo.setList(modelList);
        vo.setCount(count);
        return Result.success(vo);
    }

    @GetMapping("/doClosePublish")
    public Result<Object> doClosePublish(HttpServletRequest request, Integer postId) throws ParseException {

        String token = request.getHeader("token");
        if (token == null) {
            return Result.error(405, "token不存在");

        }
        String mobile = TokenUtils.verify(token);
        UserModel user = userService.getUserByMobile(mobile);

        if (user == null) {
            return Result.error(405, "用户不存在");
        }
        JobPublishModel jobPublish = jobPublishService.findAllJobById(Integer.valueOf(postId));
        jobPublish.setRecruitState(4);
        jobPublishService.update(jobPublish);
        return Result.success(null);
    }

    @GetMapping("/doOpenPublish")
    public Result<Object> doOpenPublish(HttpServletRequest request, Integer postId) throws ParseException {
        String token = request.getHeader("token");
        if (token == null) {
            return Result.error(405, "token不存在");

        }
        String mobile = TokenUtils.verify(token);
        UserModel user = userService.getUserByMobile(mobile);

        if (user == null) {
            return Result.error(405, "用户不存在");
        }
        JobPublishModel jobPublish = jobPublishService.findAllJobById(Integer.valueOf(postId));
        jobPublish.setRecruitState(3);
        jobPublishService.update(jobPublish);
        return Result.success(null);
    }

    //我的招聘信息
    @GetMapping("/getMyPublish")
    public Result<Object> getMyPublish(HttpServletRequest request, Integer recruitState, Integer recruitType) throws ParseException {
        String token = request.getHeader("token");
        if (token == null) {
            return Result.error(405, "token不存在");

        }
        String mobile = TokenUtils.verify(token);
        UserModel user = userService.getUserByMobile(mobile);

        if (user == null) {
            return Result.error(405, "用户不存在");
        }
        int page = Integer.valueOf(request.getParameter("page"));
        int limit = Integer.valueOf(request.getParameter("limit"));

        ComRecruitersModel com = comRecruitersService.getComRecruitersById(user.getRId());
        JobPublishModel jobPublish = new JobPublishModel();
        jobPublish.setRecId(com.getId());
        jobPublish.setRecruitState(recruitState);
        jobPublish.setRecruitType(recruitType);
        jobPublish.setPage((page - 1) * limit);
        jobPublish.setLimit(limit);
        List<JobPublishModel> modelList = jobPublishService.getJobPublishListByModel(jobPublish);

        int count = jobPublishService.getJobPublishCountByModel(jobPublish);


        for (int i = 0; i < modelList.size(); i++) {

            if (modelList.get(i).getRecruitState() == 1) {
                modelList.get(i).setRecruitStateText("待审核");
            } else if (modelList.get(i).getRecruitState() == 2) {
                modelList.get(i).setRecruitStateText("未过审");
            } else if (modelList.get(i).getRecruitState() == 3) {
                modelList.get(i).setRecruitStateText("开放中");
            } else if (modelList.get(i).getRecruitState() == 4) {
                modelList.get(i).setRecruitStateText("已关闭");
            }
        }


        if (modelList != null && modelList.size() > 0) {
            for (int i = 0; i < modelList.size(); i++) {
                int expId = modelList.get(i).getExpId();
                int eduId = modelList.get(i).getEduId();
                for (int j = 0; j < ExperienceTool.EXPERIENCE_VO_LIST.size(); j++) {
                    if (expId == ExperienceTool.EXPERIENCE_VO_LIST.get(j).getId()) {
                        modelList.get(i).setExpRequireText(ExperienceTool.EXPERIENCE_VO_LIST.get(j).getData());
                    }
                }
                for (int j = 0; j < EducationTool.EDUCATION_VO_LIST.size(); j++) {
                    if (eduId == EducationTool.EDUCATION_VO_LIST.get(j).getId()) {
                        modelList.get(i).setMinEducationText(EducationTool.EDUCATION_VO_LIST.get(j).getData());
                    }
                }

                int deliveryCount = workApplyService.getWorkApplyCountByPublishId(modelList.get(i).getId());
                modelList.get(i).setDeliveryCount(deliveryCount);
            }
        }
        JobPublishVo vo = new JobPublishVo();
        vo.setCount(count);
        vo.setList(modelList);
        return Result.success(vo);
    }

    //招聘会查询岗位信息
    @GetMapping("/getMyPublishByFair")
    public Result<Object> getMyPublishByFair(Integer comId, HttpServletRequest request) throws ParseException {
        String token = request.getHeader("token");
        UserModel user = null;
        if (token != null) {
            String mobile = TokenUtils.verify(token);
            user = userService.getUserByMobile(mobile);
        }
        int page = Integer.valueOf(request.getParameter("page"));
        int limit = Integer.valueOf(request.getParameter("limit"));

        if (comId == null && user != null) {
            ComRecruitersModel com = comRecruitersService.getComRecruitersById(user.getRId());
            comId = com.getComId();
        }

        JobPublishModel jobPublish = new JobPublishModel();
        jobPublish.setEnrollId(comId);
        jobPublish.setRecruitState(3);
        jobPublish.setRecruitType(1);
        jobPublish.setPage((page - 1) * limit);
        jobPublish.setLimit(limit);
        List<JobPublishModel> modelList = jobPublishService.getJobPublishListByModel(jobPublish);
        if (modelList != null && modelList.size() > 0) {
            for (int i = 0; i < modelList.size(); i++) {
                int expId = modelList.get(i).getExpId();
                int eduId = modelList.get(i).getEduId();
                for (int j = 0; j < ExperienceTool.EXPERIENCE_VO_LIST.size(); j++) {
                    if (expId == ExperienceTool.EXPERIENCE_VO_LIST.get(j).getId()) {
                        if (expId == 1 || expId == 6) {
                            modelList.get(i).setExpRequireText(ExperienceTool.EXPERIENCE_VO_LIST.get(j).getData());
                        } else {
                            modelList.get(i).setExpRequireText(ExperienceTool.EXPERIENCE_VO_LIST.get(j).getData() + "年");
                        }

                    }
                }
                for (int j = 0; j < EducationTool.EDUCATION_VO_LIST.size(); j++) {
                    if (eduId == EducationTool.EDUCATION_VO_LIST.get(j).getId()) {
                        modelList.get(i).setMinEducationText(EducationTool.EDUCATION_VO_LIST.get(j).getData());
                    }
                }
            }
        }
        return Result.success(modelList);
    }

    @PostMapping("/getPublishByGuessYouLove")
    public Result<Object> getPublishByGuessYouLove(Integer jobType, Integer pubId, HttpServletRequest request) throws ParseException {

        int page = Integer.valueOf(request.getParameter("page"));
        int limit = Integer.valueOf(request.getParameter("limit"));

        JobPublishModel jobPublish = new JobPublishModel();
        jobPublish.setJobType(jobType);
        jobPublish.setRecruitState(3);
        jobPublish.setLevel(3);
        jobPublish.setRecruitType(1);
        jobPublish.setPubId(pubId);
        jobPublish.setPage((page - 1) * limit);
        jobPublish.setLimit(limit);
        List<JobPublishModel> modelList = jobPublishService.getJobPublishListByModel(jobPublish);
        int count = jobPublishService.getJobPublishCountByModel(jobPublish);
        if (modelList != null) {
            for (int i = 0; i < modelList.size(); i++) {
                ComRecruitersModel com = comRecruitersService.getComRecruitersById(modelList.get(i).getRecId());
                if (com != null) {
                    EnterpriseModel enterprise = enterpriseService.findModelById(com.getComId());
                    if (enterprise.getWelfare() != null && enterprise.getWelfare() != "") {
                        String[] str = enterprise.getWelfare().split(",");
                        List<String> welfareList = new ArrayList<>();
                        for (int j = 0; j < str.length; j++) {
                            welfareList.add(str[j]);
                        }
                        enterprise.setWelfareList(welfareList);
                    }
                    com.setEnterprise(enterprise);
                    IndustryModel industryModel = industryService.getModelByCode(enterprise.getEnterpriseType());
                    enterprise.setEnterpriseTypeText(industryModel.getIndustryName());
                    for (int j = 0; j < ScaleTool.SCALE_VO_LIST.size(); j++) {
                        if (enterprise.getScaleId() == ScaleTool.SCALE_VO_LIST.get(j).getId()) {
                            enterprise.setScaleName(ScaleTool.SCALE_VO_LIST.get(j).getData());
                        }
                    }
                    com.setUser(userService.getUserByRId(com.getId()));
                    modelList.get(i).setComRecruiters(com);
                }
            }

        }
        JobPublishVo vo = new JobPublishVo();
        vo.setList(modelList);
        vo.setCount(count);
        return Result.success(vo);
    }

    //行业查询岗位
    @GetMapping("/getMyPublishByPost")
    public Result<Object> getMyPublishByPost(Integer postId, HttpServletRequest request) throws ParseException {
        String token = request.getHeader("token");
        if (token == null) {
            return Result.error(405, "token不存在");

        }
        String mobile = TokenUtils.verify(token);
        UserModel user = userService.getUserByMobile(mobile);

        if (user == null) {
            return Result.error(405, "用户不存在");
        }
        int page = Integer.valueOf(request.getParameter("page"));
        int limit = Integer.valueOf(request.getParameter("limit"));
        JobPublishModel jobPublish = new JobPublishModel();
        jobPublish.setJobType(postId);
        jobPublish.setRecruitState(3);
        jobPublish.setRecruitType(1);
        jobPublish.setPage((page - 1) * limit);
        jobPublish.setLimit(limit);
        List<JobPublishModel> modelList = jobPublishService.getJobPublishListByModel(jobPublish);
        if (modelList != null && modelList.size() > 0) {
            for (int i = 0; i < modelList.size(); i++) {
                int expId = modelList.get(i).getExpId();
                int eduId = modelList.get(i).getEduId();
                for (int j = 0; j < ExperienceTool.EXPERIENCE_VO_LIST.size(); j++) {
                    if (expId == ExperienceTool.EXPERIENCE_VO_LIST.get(j).getId()) {
                        if (expId == 1 || expId == 6) {
                            modelList.get(i).setExpRequireText(ExperienceTool.EXPERIENCE_VO_LIST.get(j).getData());
                        } else {
                            modelList.get(i).setExpRequireText(ExperienceTool.EXPERIENCE_VO_LIST.get(j).getData() + "年");
                        }

                    }
                }
                for (int j = 0; j < EducationTool.EDUCATION_VO_LIST.size(); j++) {
                    if (eduId == EducationTool.EDUCATION_VO_LIST.get(j).getId()) {
                        modelList.get(i).setMinEducationText(EducationTool.EDUCATION_VO_LIST.get(j).getData());
                    }
                }
            }
        }
        return Result.success(modelList);
    }

    //招聘会查询岗位信息
    @GetMapping("/getJobFairsPublish")
    public Result<Object> getJobFairsPublish(Integer comId, Integer sid, HttpServletRequest request) throws ParseException {
        String token = request.getHeader("token");
        if (token == null) {
            return Result.error(405, "token不存在");

        }
        String mobile = TokenUtils.verify(token);
        UserModel user = userService.getUserByMobile(mobile);

        if (user == null) {
            return Result.error(405, "用户不存在");
        }

        ComRecruitersModel com = comRecruitersService.getComRecruitersById(user.getRId());

        List<JobFairCompanyPostModel> comPostList = jobFairCompanyPostService.getListBySidAndCid(sid, comId);
        List<JobPublishModel> modelList = new ArrayList<>();
        for (int i = 0; i < comPostList.size(); i++) {
            modelList.add(jobPublishService.findAllJobById(comPostList.get(i).getPid()));
        }
        if (modelList != null && modelList.size() > 0) {
            for (int i = 0; i < modelList.size(); i++) {
                int expId = modelList.get(i).getExpId();
                int eduId = modelList.get(i).getEduId();
                for (int j = 0; j < ExperienceTool.EXPERIENCE_VO_LIST.size(); j++) {
                    if (expId == ExperienceTool.EXPERIENCE_VO_LIST.get(j).getId()) {
                        if (expId == 1 || expId == 6) {
                            modelList.get(i).setExpRequireText(ExperienceTool.EXPERIENCE_VO_LIST.get(j).getData());
                        } else {
                            modelList.get(i).setExpRequireText(ExperienceTool.EXPERIENCE_VO_LIST.get(j).getData() + "年");
                        }

                    }
                }
                for (int j = 0; j < EducationTool.EDUCATION_VO_LIST.size(); j++) {
                    if (eduId == EducationTool.EDUCATION_VO_LIST.get(j).getId()) {
                        modelList.get(i).setMinEducationText(EducationTool.EDUCATION_VO_LIST.get(j).getData());
                    }
                }
            }
        }
        return Result.success(modelList);
    }

    @GetMapping("/getJobWelfareList")
    public Result<Object> getJobWelfareList(Integer id, HttpServletRequest request) {
        String token = request.getHeader("token");
        if (token == null) {
            return Result.error(405, "token不存在");

        }
        String mobile = TokenUtils.verify(token);
        UserModel user = userService.getUserByMobile(mobile);

        if (user == null) {
            return Result.error(405, "用户不存在");
        }
        JobPublishModel jobPublish = jobPublishService.findAllJobById(Integer.valueOf(id));
        List<ExperienceVo> pubWelfareList = new ArrayList<>();
        if (jobPublish != null) {
            if (jobPublish.getWelfare() != null) {
                String[] welfareStr = jobPublish.getWelfare().split(",");
                for (int j = 0; j < welfareStr.length; j++) {
                    for (int k = 0; k < WelfareTool.SKILL_VO_LIST.size(); k++) {
                        if (WelfareTool.SKILL_VO_LIST.get(k).getData().equals(welfareStr[j])) {
                            pubWelfareList.add(WelfareTool.SKILL_VO_LIST.get(k));
                        }
                    }
                }
            }
        }
        return Result.success(pubWelfareList);
    }

    //语音模糊匹配岗位
    @PostMapping("/voiceMatching")
    public Result<Object> voiceMatching(@RequestParam("file") MultipartFile file, @RequestParam("identity") Integer identity) throws IOException, ParseException {

        String fileBase64 = Base64Utils.convertToBase64(file);
        String voice;
        SentenceRecognitionRequest req = new SentenceRecognitionRequest();
        req.setUsrAudioKey("voice");//短语音名称（随便填）
        req.setSubServiceType(2L);//2：一句话识别
        req.setProjectId(0L);
        req.setEngSerViceType("16k_zh-PY");
        req.setVoiceFormat("aac");
        req.setData(fileBase64);
        req.setSourceType(1L);
        req.setFilterPunc(1L);
        String msg = LiveUtils.SentenceRecognition(req);
        System.out.println(msg);
        JSONObject jsonObject = JSON.parseObject(msg);
        voice = jsonObject.getString("Result");
        JobPublishVo vo = new JobPublishVo();
        if (identity != null && identity == 1) {
            JobPublishModel jobPublish = new JobPublishModel();
            jobPublish.setRecruitState(3);
            List<JobPublishModel> modelList = jobPublishService.getJobPublishListByModel(jobPublish);
            List<JobPublishModel> jobPublishModelList = new ArrayList<>();
            for (int i = 0; i < modelList.size(); i++) {
                if (jobPublishModelList.size() >= 6) {
                    break;
                }
                int jobType = modelList.get(i).getJobType();
                PositionModel positionModel = positionService.getModelById(jobType);
                if (voice.toUpperCase().contains(positionModel.getJobTitle().toUpperCase())) {
                    jobPublishModelList.add(modelList.get(i));
                }
            }
            if (jobPublishModelList.size() > 0) {
                for (int i = 0; i < jobPublishModelList.size(); i++) {
                    int expId = jobPublishModelList.get(i).getExpId();
                    int eduId = jobPublishModelList.get(i).getEduId();
                    for (int j = 0; j < ExperienceTool.EXPERIENCE_VO_LIST.size(); j++) {
                        if (expId == ExperienceTool.EXPERIENCE_VO_LIST.get(j).getId()) {
                            if (expId == 1 || expId == 6) {
                                jobPublishModelList.get(i).setExpRequireText(ExperienceTool.EXPERIENCE_VO_LIST.get(j).getData());
                            } else {
                                jobPublishModelList.get(i).setExpRequireText(ExperienceTool.EXPERIENCE_VO_LIST.get(j).getData() + "年");
                            }

                        }
                    }
                    for (int j = 0; j < EducationTool.EDUCATION_VO_LIST.size(); j++) {
                        if (eduId == EducationTool.EDUCATION_VO_LIST.get(j).getId()) {
                            jobPublishModelList.get(i).setMinEducationText(EducationTool.EDUCATION_VO_LIST.get(j).getData());
                        }
                    }
                }
            }
            String sql = "select * from tb_news WHERE 1=1  ";
            if (voice != null) {
                sql += " AND (title like '%" + voice + "%' OR content like '%" + voice + "%')";
            }
            sql += "ORDER BY id DESC" + " LIMIT  " + 0 + ", " + 5 + "";
            List<Map<String, Object>> list_maps = jdbcTemplate.queryForList(sql);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            for (int i = 0; i < list_maps.size(); i++) {
                String bir = sdf.format(list_maps.get(i).get("crt_time"));
                list_maps.get(i).put("crt_time", bir);
            }
            vo.setNewsList(list_maps);
            vo.setMsg(voice);
            vo.setList(jobPublishModelList);
            return Result.success(vo);
        } else {
            String sql = "select * from tb_news WHERE 1=1  ";
            if (voice != null) {
                sql += " AND (title like '%" + voice + "%' OR content like '%" + voice + "%')";
            }
            sql += "ORDER BY id DESC" + " LIMIT  " + 0 + ", " + 5 + "";
            List<Map<String, Object>> list_maps = jdbcTemplate.queryForList(sql);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            for (int i = 0; i < list_maps.size(); i++) {
                String bir = sdf.format(list_maps.get(i).get("crt_time"));
                list_maps.get(i).put("crt_time", bir);
            }
            CustomerModel model = new CustomerModel();
            model.setKeyword(voice);
            model.setPage(0);
            model.setLimit(5);
            List<CustomerModel> customerModelList = customerMapper.getCusAndIntentionList(model);
            if (customerModelList == null || customerModelList.size() == 0) {
                vo.setCustomerList(customerModelList);
                vo.setNewsList(list_maps);
                vo.setMsg(voice);
                return Result.success(vo);
            } else {
                for (int i = 0; i < customerModelList.size(); i++) {
                    //计算年龄
                    if (customerModelList.get(i).getBirthday() != null) {
                        Timestamp time = new Timestamp(new SimpleDateFormat("yyyy-MM-dd").parse(customerModelList.get(i).getBirthday() + "-01").getTime());
                        String date = DateUtil.yearCompare(time, CommonHelp.getNowTimestamp());
                        customerModelList.get(i).setBirthday(date);
                    }

                    //判断性别
                    if (customerModelList.get(i).getSex() == 1) {
                        customerModelList.get(i).setSexText("男");
                    } else {
                        customerModelList.get(i).setSexText("女");
                    }
                    //获取学历文字
                    List<CusEducationModel> education = cusEducationService.getEducationByCustomerId(customerModelList.get(i).getId());
                    if (education == null) {
                        customerModelList.get(i).setEducationText("暂无学历");
                    } else {
                        for (int k = 0; k < EducationTool.EDUCATION_VO_LIST.size(); k++) {
                            if (education.get(0).getEducation() == EducationTool.EDUCATION_VO_LIST.get(k).getId()) {
                                customerModelList.get(i).setEducationText(EducationTool.EDUCATION_VO_LIST.get(k).getData());
                            }
                        }
                        if (customerModelList.get(i).getEducationText() == null || customerModelList.get(i).getEducationText() == "") {
                            customerModelList.get(i).setEducationText("暂无学历");
                        }
                    }

                    List<CusWorkExperienceModel> workExpList = cusWorkExperienceService.getWorkExpByCustomerId(customerModelList.get(i).getId());
                    if (workExpList != null) {
                        Timestamp time2 = new Timestamp(new SimpleDateFormat("yyyy-MM-dd").parse(workExpList.get(0).getWorkTimeStart() + "-01").getTime());
                        String date2 = DateUtil.yearCompare(time2, CommonHelp.getNowTimestamp());
                        customerModelList.get(i).setWorkTimeStart(date2 + "年");
                    } else {
                        customerModelList.get(i).setWorkTimeStart("无");
                    }
                    if (customerModelList.get(i).getJobStatus() == 1) {
                        customerModelList.get(i).setJobText("离职-随时到岗");
                    } else if (customerModelList.get(i).getJobStatus() == 2) {
                        customerModelList.get(i).setJobText("在职-月内到岗");
                    } else if (customerModelList.get(i).getJobStatus() == 3) {
                        customerModelList.get(i).setJobText("在职-考虑机会");
                    } else if (customerModelList.get(i).getJobStatus() == 4) {
                        customerModelList.get(i).setJobText("在职-暂不考虑");
                    } else {
                        customerModelList.get(i).setJobText("暂无状态");
                    }
                    Map<String, Object> map = new HashMap<>();
                    map.put("c_id", customerModelList.get(i).getId());
                    List<UserModel> userList = userMapper.selectByMap(map);
                    UserModel user = null;
                    if (userList != null && userList.size() > 0) {
                        user = userList.get(0);
                    }
                    customerModelList.get(i).setUser(user);
                    PositionModel post = positionService.getModelById(Integer.valueOf(customerModelList.get(i).getPost()));
                    customerModelList.get(i).setPostName(post.getJobTitle());
                }

                if (customerModelList != null && customerModelList.size() > 0) {
                    for (int i = 0; i < customerModelList.size(); i++) {

                        for (int j = 0; j < AreasTool.AREA_VO_LIST.size(); j++) {
                            if (Integer.valueOf(customerModelList.get(i).getRegProvince()).equals(AreasTool.AREA_VO_LIST.get(j).getId())) {
                                customerModelList.get(i).setRegProvince(AreasTool.AREA_VO_LIST.get(j).getData());
                                break;
                            }

                        }
                        for (int j = 0; j < AreasTool.AREA_VO_LIST.size(); j++) {

                            if (Integer.valueOf(customerModelList.get(i).getRegCity()).equals(AreasTool.AREA_VO_LIST.get(j).getId())) {
                                customerModelList.get(i).setRegCity(AreasTool.AREA_VO_LIST.get(j).getData());
                                break;
                            }

                        }
                        for (int j = 0; j < AreasTool.AREA_VO_LIST.size(); j++) {
                            if (Integer.valueOf(customerModelList.get(i).getRegArea()).equals(AreasTool.AREA_VO_LIST.get(j).getId())) {
                                customerModelList.get(i).setRegArea(AreasTool.AREA_VO_LIST.get(j).getData());
                                break;
                            }
                        }
                    }
                }
            }
            vo.setMsg(voice);
            vo.setCustomerList(customerModelList);
            vo.setNewsList(list_maps);
            return Result.success(vo);
        }
    }

    @GetMapping("/voiceInput")
    public Result<Object> voiceInput(Integer identity, String keyWord) throws IOException, ParseException {
        JobPublishVo vo = new JobPublishVo();
        if (identity != null && identity == 1) {
            String voice = keyWord;
            JobPublishModel jobPublish = new JobPublishModel();
            jobPublish.setRecruitState(3);
            List<JobPublishModel> modelList = jobPublishService.getJobPublishListByModel(jobPublish);
            List<JobPublishModel> jobPublishModelList = new ArrayList<>();
            for (int i = 0; i < modelList.size(); i++) {
                if (jobPublishModelList.size() >= 6) {
                    break;
                }
                int jobType = modelList.get(i).getJobType();
                PositionModel positionModel = positionService.getModelById(jobType);
                if (voice.toUpperCase().contains(positionModel.getJobTitle().toUpperCase())) {
                    jobPublishModelList.add(modelList.get(i));
                }
            }
            if (jobPublishModelList.size() > 0) {
                for (int i = 0; i < jobPublishModelList.size(); i++) {
                    int expId = jobPublishModelList.get(i).getExpId();
                    int eduId = jobPublishModelList.get(i).getEduId();
                    for (int j = 0; j < ExperienceTool.EXPERIENCE_VO_LIST.size(); j++) {
                        if (expId == ExperienceTool.EXPERIENCE_VO_LIST.get(j).getId()) {
                            if (expId == 1 || expId == 6) {
                                jobPublishModelList.get(i).setExpRequireText(ExperienceTool.EXPERIENCE_VO_LIST.get(j).getData());
                            } else {
                                jobPublishModelList.get(i).setExpRequireText(ExperienceTool.EXPERIENCE_VO_LIST.get(j).getData() + "年");
                            }

                        }
                    }
                    for (int j = 0; j < EducationTool.EDUCATION_VO_LIST.size(); j++) {
                        if (eduId == EducationTool.EDUCATION_VO_LIST.get(j).getId()) {
                            jobPublishModelList.get(i).setMinEducationText(EducationTool.EDUCATION_VO_LIST.get(j).getData());
                        }
                    }
                }
            }
            String sql = "select * from tb_news WHERE 1=1  ";
            if (keyWord != null) {
                sql += " AND (title like '%" + keyWord + "%' OR content like '%" + keyWord + "%')";
            }
            sql += "ORDER BY id DESC" + " LIMIT  " + 0 + ", " + 5 + "";
            List<Map<String, Object>> list_maps = jdbcTemplate.queryForList(sql);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            for (int i = 0; i < list_maps.size(); i++) {
                String bir = sdf.format(list_maps.get(i).get("crt_time"));
                list_maps.get(i).put("crt_time", bir);
            }
            vo.setNewsList(list_maps);
            vo.setMsg(voice);
            vo.setList(jobPublishModelList);
            return Result.success(vo);
        } else {
            String sql = "select * from tb_news WHERE 1=1  ";
            if (keyWord != null) {
                sql += " AND (title like '%" + keyWord + "%' OR content like '%" + keyWord + "%')";
            }
            sql += "ORDER BY id DESC" + " LIMIT  " + 0 + ", " + 5 + "";
            List<Map<String, Object>> list_maps = jdbcTemplate.queryForList(sql);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            for (int i = 0; i < list_maps.size(); i++) {
                String bir = sdf.format(list_maps.get(i).get("crt_time"));
                list_maps.get(i).put("crt_time", bir);
            }
            CustomerModel model = new CustomerModel();
            model.setKeyword(keyWord);
            model.setPage(0);
            model.setLimit(5);
            List<CustomerModel> customerModelList = customerMapper.getCusAndIntentionList(model);
            if (customerModelList == null || customerModelList.size() == 0) {
                vo.setCustomerList(customerModelList);
                vo.setNewsList(list_maps);
                vo.setMsg(keyWord);
                return Result.success(vo);
            } else {
                for (int i = 0; i < customerModelList.size(); i++) {
                    //计算年龄
                    if (customerModelList.get(i).getBirthday() != null) {
                        Timestamp time = new Timestamp(new SimpleDateFormat("yyyy-MM-dd").parse(customerModelList.get(i).getBirthday() + "-01").getTime());
                        String date = DateUtil.yearCompare(time, CommonHelp.getNowTimestamp());
                        customerModelList.get(i).setBirthday(date);
                    }

                    //判断性别
                    if (customerModelList.get(i).getSex() == 1) {
                        customerModelList.get(i).setSexText("男");
                    } else {
                        customerModelList.get(i).setSexText("女");
                    }
                    //获取学历文字
                    List<CusEducationModel> education = cusEducationService.getEducationByCustomerId(customerModelList.get(i).getId());
                    if (education == null) {
                        customerModelList.get(i).setEducationText("暂无学历");
                    } else {
                        for (int k = 0; k < EducationTool.EDUCATION_VO_LIST.size(); k++) {
                            if (education.get(0).getEducation() == EducationTool.EDUCATION_VO_LIST.get(k).getId()) {
                                customerModelList.get(i).setEducationText(EducationTool.EDUCATION_VO_LIST.get(k).getData());
                            }
                        }
                        if (customerModelList.get(i).getEducationText() == null || customerModelList.get(i).getEducationText() == "") {
                            customerModelList.get(i).setEducationText("暂无学历");
                        }
                    }

                    List<CusWorkExperienceModel> workExpList = cusWorkExperienceService.getWorkExpByCustomerId(customerModelList.get(i).getId());
                    if (workExpList != null) {
                        Timestamp time2 = new Timestamp(new SimpleDateFormat("yyyy-MM-dd").parse(workExpList.get(0).getWorkTimeStart() + "-01").getTime());
                        String date2 = DateUtil.yearCompare(time2, CommonHelp.getNowTimestamp());
                        customerModelList.get(i).setWorkTimeStart(date2 + "年");
                    } else {
                        customerModelList.get(i).setWorkTimeStart("无");
                    }
                    if (customerModelList.get(i).getJobStatus() == 1) {
                        customerModelList.get(i).setJobText("离职-随时到岗");
                    } else if (customerModelList.get(i).getJobStatus() == 2) {
                        customerModelList.get(i).setJobText("在职-月内到岗");
                    } else if (customerModelList.get(i).getJobStatus() == 3) {
                        customerModelList.get(i).setJobText("在职-考虑机会");
                    } else if (customerModelList.get(i).getJobStatus() == 4) {
                        customerModelList.get(i).setJobText("在职-暂不考虑");
                    } else {
                        customerModelList.get(i).setJobText("暂无状态");
                    }
                    Map<String, Object> map = new HashMap<>();
                    map.put("c_id", customerModelList.get(i).getId());
                    List<UserModel> userList = userMapper.selectByMap(map);
                    UserModel user = null;
                    if (userList != null && userList.size() > 0) {
                        user = userList.get(0);
                    }
                    customerModelList.get(i).setUser(user);
                    PositionModel post = positionService.getModelById(Integer.valueOf(customerModelList.get(i).getPost()));
                    customerModelList.get(i).setPostName(post.getJobTitle());
                }

                if (customerModelList != null && customerModelList.size() > 0) {
                    for (int i = 0; i < customerModelList.size(); i++) {

                        for (int j = 0; j < AreasTool.AREA_VO_LIST.size(); j++) {
                            if (Integer.valueOf(customerModelList.get(i).getRegProvince()).equals(AreasTool.AREA_VO_LIST.get(j).getId())) {
                                customerModelList.get(i).setRegProvince(AreasTool.AREA_VO_LIST.get(j).getData());
                                break;
                            }

                        }
                        for (int j = 0; j < AreasTool.AREA_VO_LIST.size(); j++) {

                            if (Integer.valueOf(customerModelList.get(i).getRegCity()).equals(AreasTool.AREA_VO_LIST.get(j).getId())) {
                                customerModelList.get(i).setRegCity(AreasTool.AREA_VO_LIST.get(j).getData());
                                break;
                            }

                        }
                        for (int j = 0; j < AreasTool.AREA_VO_LIST.size(); j++) {
                            if (Integer.valueOf(customerModelList.get(i).getRegArea()).equals(AreasTool.AREA_VO_LIST.get(j).getId())) {
                                customerModelList.get(i).setRegArea(AreasTool.AREA_VO_LIST.get(j).getData());
                                break;
                            }
                        }
                    }
                }
            }
            vo.setCustomerList(customerModelList);
            vo.setNewsList(list_maps);
            vo.setMsg(keyWord);
            return Result.success(vo);
        }
    }

    @GetMapping("doJobPublishShare")
    public Result<Object> doJobPublishShare(HttpServletRequest request,Integer id) throws Exception {

        String token = request.getHeader("token");
        UserModel user = null;
        if (token != null) {
            String mobile = TokenUtils.verify(token);
            user = userService.getUserByMobile(mobile);
        }
        JobPublishModel jobPublish = (JobPublishModel) jobPublishService.selectJobsById(id, user);
        //生成二维码
        Long date = Calendar.getInstance().getTimeInMillis() / 1000;
        WxQrCode.generateQrCode("" + SystemConstant.DEFAULT_PDF_URL + "/jobQrcode/" + id + date + ".png", "page_other/job_hunting/job_detail/index", "id=" + id + "&share=1", WxQrCode.redisToken());
        String srcImgPath = "" + SystemConstant.DEFAULT_PDF_URL + "/share/publish.jpg";    //源图片地址
        String tarImgPath = "" + SystemConstant.DEFAULT_PDF_URL + "/share2/" + id + date + ".png";   //目标图片的地址

        //获取数据集合；
        ArrayList<ImageDTO> list = new ArrayList<>();
        list.add(WaterMarkUtils.createImageDTO(jobPublish.getMinSalary()+"-"+jobPublish.getMaxSalary()+"元",new Color(16,156,151),new Font("微软雅黑", Font.PLAIN, 42), 90, 1200));
        list.add(WaterMarkUtils.createImageDTO(jobPublish.getJobTitle(), new Color(25, 25, 25), new Font("微软雅黑", Font.PLAIN, 42), 90, 1270));
        String address = "酒泉 · "+jobPublish.getExpRequireText()+" · "+jobPublish.getMinEducationText();
        list.add(WaterMarkUtils.createImageDTO(address, new Color(98, 96, 99), new Font("微软雅黑", Font.PLAIN, 26), 90, 1320));
        String realName = jobPublish.getComRecruiters().getRealName();
        list.add(WaterMarkUtils.createImageDTO(realName, new Color(25, 25, 25), new Font("微软雅黑", Font.PLAIN, 42), 190, 1440));
        String content = jobPublish.getComRecruiters().getEnterprise().getBrandName()+" · "+jobPublish.getComRecruiters().getComPosition();
        list.add(WaterMarkUtils.createImageDTO(content, new Color(25, 25, 25), new Font("微软雅黑", Font.PLAIN, 24), 190, 1480));
        //操作图片:
        WaterMarkUtils.writeImage(srcImgPath, tarImgPath, list);
        // 图片路径
        // 水印图片路径
        String iconPath = "" + SystemConstant.DEFAULT_PDF_URL + "/jobQrcode/" + id + date + ".png";

        WaterMarkUtils.ImageWatermark(iconPath, tarImgPath, tarImgPath, null);
        String url = SystemConstant.DEFAULT_UPLOAD_SERVICE_URL+"/share2/" + id + date + ".png";
        return Result.success(url);

    }
    //岗位推荐
    @GetMapping("/jobRecommendation")
    public Result<Object> jobRecommendation(Integer page, Integer limit, Double longitude, Double latitude, HttpServletRequest request) {
        String token = request.getHeader("token");
        if (token == null) {
            return Result.error(405, "token不存在");
        }
        String mobile = TokenUtils.verify(token);
        UserModel user = userService.getUserByMobile(mobile);
        if (user == null) {
            return Result.error(405, "用户不存在");
        }
        if (user.getCId() == null) {
            return Result.success(null);
        }
        List<JobIntentionModel> intentionModelList = jobIntentionService.getIntentionListByCustomerId(user.getCId());
        if (intentionModelList == null || intentionModelList.isEmpty()) {
            return Result.success(null);
        }
        List<Integer> integerList = new ArrayList<>();
        for (int i = 0; i < intentionModelList.size(); i++) {
            integerList.add(intentionModelList.get(i).getPost());
        }
        JobPublishVo jobPublishCountByPost = jobPublishService.getJobPublishCountByPost(integerList, page, limit);
        if (jobPublishCountByPost.getList() != null) {
            List<ComResumeNumberModel> crnModelList = comResumeNumberService.getAllList();
            for (int i = 0; i < jobPublishCountByPost.getList().size(); i++) {
                jobPublishCountByPost.getList().get(i).setJobTypeText(positionService.getModelById(jobPublishCountByPost.getList().get(i).getJobType()).getJobTitle());
                ComRecruitersModel com = comRecruitersService.getComRecruitersById(jobPublishCountByPost.getList().get(i).getRecId());
                if (com != null) {
                    EnterpriseModel enterprise = enterpriseService.findModelById(com.getComId());
                    if (enterprise.getWelfare() != null && enterprise.getWelfare() != "") {
                        String[] str = enterprise.getWelfare().split(",");
                        List<String> welfareList = new ArrayList<>();
                        for (int j = 0; j < str.length; j++) {
                            welfareList.add(str[j]);
                        }
                        enterprise.setWelfareList(welfareList);
                    }
                    com.setEnterprise(enterprise);
                    IndustryModel industryModel = industryService.getModelByCode(enterprise.getEnterpriseType());
                    if (industryModel != null) {
                        enterprise.setEnterpriseTypeText(industryModel.getIndustryName());
                    }
                    for (int j = 0; j < ScaleTool.SCALE_VO_LIST.size(); j++) {
                        if (enterprise.getScaleId() != null && enterprise.getScaleId() == ScaleTool.SCALE_VO_LIST.get(j).getId()) {
                            enterprise.setScaleName(ScaleTool.SCALE_VO_LIST.get(j).getData());
                        }
                    }
                    com.setUser(userService.getUserByRId(com.getId()));
                    jobPublishCountByPost.getList().get(i).setComRecruiters(com);
                }
                if (latitude != null && longitude != null) {
                    double haversine = CalculateDistance.haversine(longitude, latitude, jobPublishCountByPost.getList().get(i).getLongitude(), jobPublishCountByPost.getList().get(i).getLatitude());
                    if (haversine != 0) {
                        DecimalFormat df = new DecimalFormat("0.0");
                        String formatted = df.format(haversine);
                        jobPublishCountByPost.getList().get(i).setDistances(formatted);
                    }
                }
                for (int j = 0; j < crnModelList.size(); j++) {
                    if (jobPublishCountByPost.getList().get(i).getId() == crnModelList.get(j).getPid()) {
                        if (crnModelList.get(j).getNumber() >= 3) {
                            jobPublishCountByPost.getList().get(i).setIsHeat(1);
                        }
                    }
                }
            }

        }
        return Result.success(jobPublishCountByPost);
    }

    //招聘会推荐
    @GetMapping("/jobFairRecommendation")
    public Result<Object> jobFairRecommendation(Integer page, Integer limit, HttpServletRequest request) {
        String token = request.getHeader("token");
        if (token == null) {
            return Result.error(405, "token不存在");
        }
        String mobile = TokenUtils.verify(token);
        UserModel user = userService.getUserByMobile(mobile);
        if (user == null) {
            return Result.error(405, "用户不存在");
        }
        JobFairSceneVo vo = jobFairSceneService.jobFairRecommendation(page, limit);
        if (vo.getList() != null) {
            for (int i = 0; i < vo.getList().size(); i++) {
                if (vo.getList().get(i) != null) {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                    Timestamp data = Timestamp.valueOf(vo.getList().get(i).getEventTimeStart());
                    Timestamp data2 = Timestamp.valueOf(vo.getList().get(i).getEventTimeEnd());
                    String starTime = sdf.format(data);
                    String endTime = sdf.format(data2);
                    vo.getList().get(i).setEventTimeStart(starTime);
                    vo.getList().get(i).setEventTimeEnd(endTime);
                    vo.getList().get(i).setQyCount(jobFairCompanyService.countByCid(vo.getList().get(i).getId()));
                    int countPost = jobFairCompanyPostService.countBySid(vo.getList().get(i).getId());
                    vo.getList().get(i).setZwCount(countPost);
                    vo.getList().get(i).setBrowseNumber(vo.getList().get(i).getBrowseNumber() + 1);
                    vo.getList().get(i).setResumeCount(jobFairCompanyService.countByResume(vo.getList().get(i).getId()));
                    if (data.getTime() > CommonHelp.getNowTimestamp().getTime()) {
                        vo.getList().get(i).setState(1);
                    }
                    if (data.getTime() < CommonHelp.getNowTimestamp().getTime() && data2.getTime() > CommonHelp.getNowTimestamp().getTime()) {
                        vo.getList().get(i).setState(2);
                    }
                    if (data2.getTime() < CommonHelp.getNowTimestamp().getTime()) {
                        vo.getList().get(i).setState(3);
                    }
                }
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                Timestamp data = Timestamp.valueOf(vo.getList().get(i).getCrtTime());
                String currentSimpleDateFormat = simpleDateFormat.format(data);
                vo.getList().get(i).setCrtTime(currentSimpleDateFormat);
                String[] str = vo.getList().get(i).getSceneType().split(",");
                StringBuilder sceneTypeText = new StringBuilder();
                for (int j = 0; j < str.length; j++) {
                    if (str[j].equals("1")) {
                        sceneTypeText.append("现场招聘,");
                    }
                    if (str[j].equals("2")) {
                        sceneTypeText.append("网络招聘,");
                    }
                    if (str[j].equals("3")) {
                        sceneTypeText.append("校园招聘,");
                    }
                }
                vo.getList().get(i).setSceneTypeText(sceneTypeText.toString());
                vo.getList().get(i).setQyCount(jobFairCompanyService.countBySid(vo.getList().get(i).getId()));
            }
        }
        return Result.success(vo);
    }

    //推荐培训机构
    @GetMapping("/trainRecommendation")
    public Result<Object> trainList(Integer page, Integer limit, HttpServletRequest request) {
        String token = request.getHeader("token");
        if (token == null) {
            return Result.error(405, "token不存在");
        }
        String mobile = TokenUtils.verify(token);
        UserModel user = userService.getUserByMobile(mobile);
        if (user == null) {
            return Result.error(405, "用户不存在");
        }
        if (user.getCId() == null) {
            return Result.success(null);
        }
        List<JobIntentionModel> intentionModelList = jobIntentionService.getIntentionListByCustomerId(user.getCId());
        if (intentionModelList == null || intentionModelList.isEmpty()) {
            return Result.success(null);
        }
        List<Integer> integerList = new ArrayList<>();
        for (int i = 0; i < intentionModelList.size(); i++) {
            integerList.add(intentionModelList.get(i).getPost());
        }
        return Result.success(skillTrainingService.trainRecommendation(page, limit, integerList));
    }
}
